home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #43 (Apr 89) / XCMDSource Code / ADSPCall.p next >
Text File  |  1989-02-13  |  5KB  |  220 lines

  1. (********************************)
  2. (*    file:         ADSPCall.p                *)
  3. (*                                                             *)
  4. (* Establish a connection with    *)
  5. (* the entity whose name is            *)
  6. (* passed as a parameter.                *)
  7. (*                                                            *)
  8. (*                                                            *)
  9. (* params[1] = Name of entity     *)
  10. (* params[2] = listen message        *)
  11. (* params[3] = number of retries*)
  12. (* params[4] = retry interval        *)
  13. (* params[5] = Input buffer siz    *)
  14. (* params[6] = Output buffer siz*)
  15. (*                                                            *)
  16. (* If  already connected, just    *)
  17. (* return with noErr                         *)
  18. (*                                                             *)
  19. (* Defaults:                                        *)
  20. (* Input Buffer     = 578                    *)
  21. (* Output Buffer    = 578                    *)
  22. (* Retry count        = 0                        *)
  23. (* Retry interval    = 0                        *)
  24. (* Out:    the Result ::= error         *)
  25. (*    message, empty if none.            *)
  26. (*                                                            *)
  27. (* ----------------------------    *)
  28. (* By:        Donald Koscheka                *)
  29. (* Date:    9-Jan-89                            *)
  30. (*            All Rights Reserved            *)
  31. (*                                                            *)
  32. (********************************)
  33.  
  34.  
  35. (********************************
  36.             Build Sequence
  37.  
  38. pascal ADSPCall.p -o ADSPCall.p.o 
  39. link -m ENTRYPOINT  -rt XCMD=1302 -sn Main=ADSPCall∂
  40.     ADSPCall.p.o∂
  41.     "{libraries}"Interface.o ∂
  42.     -o YourStackNameHere
  43.  
  44.  
  45.          
  46. *********************************)
  47.  
  48.  
  49. {$R-}
  50. {$S ADSPCall}
  51. UNIT Koscheka;
  52.  
  53. (*********************************)
  54.                     INTERFACE 
  55. (*********************************)
  56.  
  57.  
  58. Uses    MemTypes, QuickDraw, OSIntf, 
  59.         ToolIntf, PackIntf, HyperXCmd,
  60.         AppleTalk, ADSP, adspxcmd;
  61.  
  62.  
  63. Procedure EntryPoint( paramPtr : XCmdPtr );
  64.  
  65.  
  66. (*********************************)
  67.                 IMPLEMENTATION
  68. (*********************************)
  69. TYPE Str31 = String[31];
  70.  
  71.  
  72. PROCEDURE ADSPCall( paramPtr: XCmdPtr ); FORWARD;
  73.  
  74. Procedure EntryPoint( paramPtr : XCmdPtr );
  75. Begin
  76.     ADSPCall( paramPtr );
  77. End;
  78.     
  79.     
  80. Procedure ADSPCall( paramPtr : XCmdPtr );
  81. VAR
  82.     adsp                : ADSPPtr;
  83.     error, terr    : OSErr;
  84.     inBufSiz        : Integer;
  85.     outBufSiz        : Integer;
  86.     retry                : Integer;
  87.     interval        : Integer;
  88.     eAddr                : AddrBlock;    
  89.     cn                    : CBPtr;
  90.     nbp                 : NBPPtr;
  91.     found                : BOOLEAN;
  92.     
  93. {$I XCmdGlue.inc }
  94. {$I XCMDADSP.inc }    
  95.  
  96. (*********************************)
  97. BEGIN
  98.     error         := noErr;
  99.     found            := TRUE;    {*** true if  already established ***}
  100.     
  101. WITH paramPtr^ DO
  102. BEGIN
  103.     IF (paramCount <> 0) AND (params[1]^ <> NIL) THEN    
  104.     BEGIN
  105.         adsp := ADSPPtr(RetrieveData( 'GLOBALDSPDATA' ));
  106.         IF adsp <> NIL THEN
  107.         BEGIN
  108.             adsp^.checkPoint := RECEIVING;
  109.             
  110.             {**** Before we go too far, let's     ***}
  111.             {*** look at some of the settings        ***}
  112.             {*** set the retransmit count                ***}
  113.             IF params[3] <> NIL THEN
  114.                 retry := StringToSHort( params[3]^ )
  115.             ELSE
  116.                 retry    := 0;
  117.         
  118.             {*** Set the retransmit interval    ***}
  119.             IF params[4] <> NIL THEN    
  120.                 interval := StringToSHort( params[4]^ )
  121.             ELSE
  122.                 interval := 0;
  123.         
  124.             {*** Set the input buffer size        ***}
  125.             IF params[5] <> NIL THEN
  126.                 inBufSiz := StringToSHort( params[5]^ )
  127.             ELSE
  128.                 inBufSiz := ATPBSIZE;
  129.         
  130.             {*** Set the output buffer size        ***}
  131.             IF params[6] <> NIL THEN
  132.                 outBufSiz := StringToSHort( params[6]^ )
  133.             ELSE
  134.                 outBufSiz    := ATPBSIZE;
  135.             
  136.             {*** (1) Get the entity's address    ***}
  137.             HLock( Handle( params[1]) );
  138.             eAddr := NBPGetAddress( params[1]^ );
  139.             HUnlock( Handle( params[1] ) );
  140.  
  141.             {*** Walk through the connection         ***}
  142.             {*** list to see if the connection    ***}
  143.             {*** already exists.                                ***}
  144.             
  145.             IF LongInt(eAddr) <> 0 THEN
  146.             BEGIN
  147.                 cn := adsp^.ends;
  148.                 found := FALSE;
  149.                 
  150.                 WHILE (NOT found) DO
  151.                 IF cn = NIL THEN
  152.                     found := TRUE
  153.                 ELSE
  154.                 IF LongInt( eAddr ) = LongInt( cn^.adr ) THEN
  155.                     found := TRUE
  156.                 ELSE
  157.                     cn := cn^.next;
  158.                 
  159.                 {*** If the connection already exists    ***}
  160.                 {*** cn will not be NIL  so we won't     ***}
  161.                 {*** have to reconnect the two ends,    ***}
  162.                 {*** just fall out, otherwise, try to    ***}
  163.                 {*** make the connection.                ***}
  164.                 
  165.                 IF cn = NIL  THEN {*** establish connection ***}
  166.                 BEGIN
  167.                     cn^.remName    := NBPGetName( eAddr );
  168.                     cn := DSPCreate(eAddr,inBufSiz,
  169.                                                     outBufSiz,retry,
  170.                                                     interval,params[2] );
  171.                     IF cn <> NIL THEN
  172.                     BEGIN
  173.                         cn^.remName := NBPGetName( eAddr );
  174.                         
  175.                         {*** try to discover the name     ***}
  176.                         IF cn^.remName = NIL THEN    
  177.                         BEGIN
  178.                             nbp := NBPPtr(RetrieveData('GLOBALNBPDATA'));
  179.                             IF nbp <> NIL THEN 
  180.                             BEGIN
  181.                                 SendCardMessage('DoALookUp');
  182.                                 cn^.remName := NBPGetName( eAddr );
  183.                             END;
  184.                         END;
  185.     
  186.                         {*** Now "dial for dollars"    ***}
  187.                         WITH cn^.dspPB DO    
  188.                         BEGIN
  189.                             ioCRefNum     := adsp^.dspRefNum;
  190.                             ccbRefNum    := cn^.ccbRef;
  191.                             csCode        := dspOpen;
  192.                             ocMode        := ocRequest;
  193.                             ioCompletion:= NIL;
  194.                             remoteCID    := 0;        {*** don't know this yet    ***}
  195.                             localCID    := 0;        {*** adsp allocates the id    ***}
  196.                             remoteAddress:= eAddr;    
  197.                             filterAddress.aNet    := 0;
  198.                             filterAddress.aNode    := 0;
  199.                             filterAddress.aSocket:= 0;
  200.                             SendSeq        := 0;
  201.                             RecvSeq        := 0;
  202.                             SendWindow    := 0;
  203.                             attnSendSeq    := 0;
  204.                             attnRecvSeq    := 0;
  205.                             ocInterval    := INTERVAL;
  206.                             ocMaximum    := RETRY;
  207.                             error         := PBControl( @cn^.dspPB, ASYNC );
  208.                         END;
  209.                     END;
  210.                 END;
  211.             END; {(LongInt(eAddr) <> 0) }
  212.             adsp^.checkPoint := CLOSE_OK;
  213.         END;
  214.     END;
  215.     returnValue := PasToZero( NumToStr( LongInt(error) ) );
  216. END; {*** with paramPtr^ ***}
  217. END;
  218.  
  219. end.
  220.